
import express, { Request, Response } from "express"
import adminRouter from "./adminRouter/adminRouter"
import appRouter from "./appRouter/appRouter"
import { checkToken } from "../utils/token"
import { checkUserState } from "../utils/userState"
import { upload } from "../utils/upload";

const allRouter = express.Router()

allRouter.use("/admin", checkToken, checkUserState, adminRouter)
allRouter.post("/admin/upload",  async (req: Request, res: Response)=>{
  try {
    const urlName =  await upload(req)
    res.send({
      code: 1,
      msg: "上传成功！", 
      data: urlName
    })
  } catch (e) {
    res.send({
      code: 0,
      msg:"失败了"
    })
  }
})
//allRouter.use("/admin", adminRouter)
allRouter.use("/app", appRouter)

export default allRouter